package com.turi.vo;

import com.turi.enums.ResultEnum;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * REST接口返回值
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class ResultVO<T> {

    /**
     * 响应码
     */
    private Integer code;

    /**
     * 响应消息
     */
    private String message;

    /**
     * 响应数据
     */
    private T data;

    /**
     * 执行成功后调用
     */
    public static <T> ResultVO<T> success() {
        return success(null);
    }

    /**
     * 执行成功后调用
     *
     * @return 响应数据
     */
    public static <T> ResultVO<T> success(T data) {
        return new ResultVO<>(ResultEnum.SUCCESS.getCode(), ResultEnum.SUCCESS.getMessage(), data);
    }

    public static <T> ResultVO<T> failed() {
        return failed(ResultEnum.SYSTEM_ERROR);
    }

    public static <T> ResultVO<T> failed(ResultEnum resultEnum) {
        return failed(resultEnum.getCode(), resultEnum.getMessage());
    }

    public static <T> ResultVO<T> failed(String message) {
        return failed(ResultEnum.SYSTEM_ERROR.getCode(), message);
    }

    public static <T> ResultVO<T> failed(int code, String message) {
        return new ResultVO<>(code, message, null);
    }
}
